//
//  MainViewController.swift
//  Weibo
//
//  Created by 李洋 on 15/12/12.
//  Copyright © 2015年 Leon. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    let mainTabBar = MainTabBar()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //使用自定义的 tabbar
        
        //tabBar 是只读属性  不能直接赋值 可使用 KVC 进行赋值
        setValue(mainTabBar, forKey: "tabBar")
        
        mainTabBar.composeBtn.addTarget(self, action: "composeBtnClick", forControlEvents: .TouchUpInside)
        //print(tabBar.classForCoder)
        //添加子视图控制器
        addChildViewControllers()
        
    }
    
    //加号按钮的点击事件
    @objc private func composeBtnClick(){
        
    }
    
    private func addChildViewControllers() {
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
    }
    private func addChildViewController(childController: UIViewController,title:String,imageName:String) {
        self.tabBar.tintColor = themeColor
        let VC = childController
        let nav = UINavigationController(rootViewController: VC)
        VC.title = title
        nav.tabBarItem.image = UIImage(named: imageName)
        addChildViewController(nav)
    }
    
    
}
